<html>
<head>
<title>DBHelper.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { }
.s2 { color: rgb(128,128,128); font-style: italic; }
.s3 { color: rgb(128,128,128); font-weight: bold; font-style: italic; }
.s4 { color: rgb(0,128,0); font-weight: bold; }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
DBHelper.java</FONT>
</center></TD></TR></TABLE>
<pre>

<span class="s0">package </span><span class="s1">com.example.lista_zakupow.database; 
 
</span><span class="s0">import </span><span class="s1">android.content.Context; 
</span><span class="s0">import </span><span class="s1">android.database.sqlite.SQLiteDatabase; 
</span><span class="s0">import </span><span class="s1">android.database.sqlite.SQLiteOpenHelper; 
</span><span class="s0">import </span><span class="s1">android.util.Log; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.query.DatabaseQueryStrings; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.tables_headers.ListaZakupowTableHeaders; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.tables_headers.ProduktyTableHeaders; 
 
</span><span class="s0">import </span><span class="s1">java.util.Locale; 
 
</span><span class="s0">public class </span><span class="s1">DBHelper </span><span class="s0">extends </span><span class="s1">SQLiteOpenHelper { 
    </span><span class="s0">private static final </span><span class="s1">String DEBUG_TAG = DBHelper.</span><span class="s0">class</span><span class="s1">.getSimpleName(); 
 
    </span><span class="s0">private int </span><span class="s1">version; 
 
    </span><span class="s2">/** 
     * Klasa pomocna przy tworzeniu/ zmiany bazy danych 
     * </span><span class="s3">@param </span><span class="s2">context Context aplikacji 
     * </span><span class="s3">@param </span><span class="s2">name nazwa bazy danych 
     * </span><span class="s3">@param </span><span class="s2">version wersja bazy danych 
     */</span><span class="s1"> 
    </span><span class="s0">public </span><span class="s1">DBHelper(Context context, String name, </span><span class="s0">int </span><span class="s1">version) { 
        </span><span class="s0">super</span><span class="s1">(context, name, </span><span class="s0">null</span><span class="s1">, version); 
        </span><span class="s0">this</span><span class="s1">.version = version; 
    } 
 
    @Override 
    </span><span class="s0">public void </span><span class="s1">onCreate(SQLiteDatabase db) { 
        Log.d(DEBUG_TAG, </span><span class="s4">&quot;Tworzenie nowej bazy danych...&quot;</span><span class="s1">); 
        db.execSQL(DatabaseQueryStrings.CREATE_LIST_TABLE); 
        db.execSQL(DatabaseQueryStrings.CREATE_PRODUCTS_TABLE); 
        </span><span class="s2">// ustawienia lokalne.</span><span class="s1"> 
        db.setLocale(Locale.getDefault()); 
        </span><span class="s2">// Przystosowanie SQLiteDatabase do pracy wielowątkowej</span><span class="s1"> 
        </span><span class="s2">// poprzez zastosowanie blokad w kluczowych sekcjach.</span><span class="s1"> 
        db.setLockingEnabled(</span><span class="s0">true</span><span class="s1">); 
        </span><span class="s2">// Ustawienie wersji bazy.</span><span class="s1"> 
        db.setVersion(version); 
 
        </span><span class="s2">// Zarejestrowanie pewnych informacji o naszej bazie danych.</span><span class="s1"> 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Utworzono bazę danych: &quot; </span><span class="s1">+ db.getPath()); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Wersja bazy danych: &quot; </span><span class="s1">+ db.getVersion()); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Wielkość strony bazy danych: &quot; </span><span class="s1">+ db.getPageSize()); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Maksymalna wielkość bazy danych: &quot; </span><span class="s1">+ db.getMaximumSize()); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Baza jest otworzona: &quot; </span><span class="s1">+ db.isOpen()); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Baza tylko do odczytu: &quot; </span><span class="s1">+ db.isReadOnly()); 
    } 
 
    @Override 
    </span><span class="s0">public void </span><span class="s1">onUpgrade(SQLiteDatabase db, </span><span class="s0">int </span><span class="s1">oldVersion, </span><span class="s0">int </span><span class="s1">newVersion) { 
        db.execSQL(DatabaseQueryStrings.DROP_LIST_TABLE); 
        db.execSQL(DatabaseQueryStrings.DROP_PRODUCTS_TABLE); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Usuniecie tabeli: &quot; </span><span class="s1">+ ListaZakupowTableHeaders.TABLE_NAME); 
        Log.i(DEBUG_TAG, </span><span class="s4">&quot;Usuniecie tabeli: &quot; </span><span class="s1">+ ProduktyTableHeaders.TABLE_NAME); 
        Log.d(DEBUG_TAG, </span><span class="s4">&quot;Aktualizacja bazy danych z ver.&quot; </span><span class="s1">+ oldVersion + </span><span class="s4">&quot; do ver.&quot; </span><span class="s1">+ newVersion); 
        onCreate(db); 
    } 
}</span></pre>
</body>
</html>